﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

namespace WebSite_CodeMan.Sys_CodeMan_Manage
{
    public partial class Admin_Class_Mes : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BaseClass.BaseClass.CheckState();
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            RpProduct.DataSource = BLL.NoteInfo.GetNoteClassMes("");
            RpProduct.DataBind();
        }
        /// <summary>
        /// 返回类型名称的等级
        /// </summary>
        /// <param name="strClassName"></param>
        /// <param name="strLeave"></param>
        /// <returns></returns>
        protected string CheckClassNameLeave(object strClassName, object strLeave)
        {
            string strMes = strClassName.ToString();
            string[] strName = strLeave.ToString().Split(',');
            string[] strTop = { "", "&nbsp;&nbsp;┗━", "&nbsp;&nbsp;&nbsp;&nbsp;┗━", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;┗━", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;┗━", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;┗━" };
            strMes = (strName.Length == 1) ? "<div class=\"TopClass\">" + strMes + "</div>" : (strTop[strName.Length - 1] + strMes);
            return strMes;
        }

        protected void RpProduct_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName=="Del")
            {
                //todo 用下划线 则模块名字不能以下划线分割 fix later
                string[] strMes = e.CommandArgument.ToString().Split('_');
                if (strMes.Length == 3)
                {
                    if (BLL.NoteInfo.DelClassMes(strMes[0], strMes[1]))
                    {
                        DelNoteFiles(strMes[1], strMes[2]);
                        Common.MessageBox.Show(Page, "相关所有信息删除成功...", "Admin_Class_Mes.aspx", "suess");
                    }
                    else 
                    {
                        Common.MessageBox.Show(Page, "相关所有信息删除失败，请重试或联系技术人员...", "Admin_Class_Mes.aspx", "Err");
                    }
                }
                else
                {
                    Common.MessageBox.Show(Page, "关键参数不足，不能执行删除操作...","Admin_Class_Mes.aspx", "error");
                }
            }
        }

        /// <summary>
        /// 删完数据还得删文件
        /// </summary>
        /// <param name="strClassID"></param>
        private void DelNoteFiles(string strLeave,string strEnName)
        {
            OleDbDataReader DataRead = BLL.NoteInfo.GetNoteID(strLeave);
            if (DataRead.HasRows)
            {
                while (DataRead.Read())
                {
                    //todo 用列表的形式循环 待改进
                    Common.FileComm.DeleteFile(Server.MapPath("~/UpLoad/Images/" + DataRead["T_NoteID"].ToString() + ".gif"));
                    Common.FileComm.DeleteFile(Server.MapPath("~/UpLoad/Images/" + DataRead["T_NoteID"].ToString() + ".jpg"));
                    Common.FileComm.DeleteFile(Server.MapPath("~/UpLoad/Images/" + DataRead["T_NoteID"].ToString() + ".bmp"));
                    Common.FileComm.DeleteFile(Server.MapPath("~/UpLoad/Images/" + DataRead["T_NoteID"].ToString() + ".png"));

                    Common.FileComm.DeleteFile(Server.MapPath("~/UpLoad/Images/Small/" + DataRead["T_NoteID"].ToString() + ".jpg"));
                    Common.FileComm.DeleteFile(Server.MapPath("~/UpLoad/Images/Small/" + DataRead["T_NoteID"].ToString() + ".gif"));

                    Common.FileComm.DeleteFile(Server.MapPath("~/UpLoad/Files/" + DataRead["T_NoteID"].ToString() + ".doc"));
                    Common.FileComm.DeleteFile(Server.MapPath("~/UpLoad/Files/" + DataRead["T_NoteID"].ToString() + ".rar"));
                    Common.FileComm.DeleteFile(Server.MapPath("~/UpLoad/Files/" + DataRead["T_NoteID"].ToString() + ".zip"));
                    Common.FileComm.DeleteFile(Server.MapPath("~/UpLoad/Files/" + DataRead["T_NoteID"].ToString() + ".pdf"));
                    Common.FileComm.DeleteFile(Server.MapPath("~/UpLoad/Files/" + DataRead["T_NoteID"].ToString() + ".swf"));
                }
            }
            DataRead.Close();
            DataRead.Dispose();
            if (!string.IsNullOrEmpty(strEnName))
            {
                Common.FileComm.DeleteFolder(Server.MapPath("~/" + strEnName + "/"));
            }
        }
    }
}
